/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.services.Impl;

import com.startup.musicstore.model.Album;
import com.startup.musicstore.model.Customer;
import com.startup.musicstore.model.OrderItem;
import com.startup.musicstore.model.Orders;
import com.startup.musicstore.services.GenderPurchaseService;
import com.startup.musicstore.services.crud.CustomerCrudService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author linda
 */
@Service("genderPurchaseService")
@Transactional
public class GenderPurchaseServiceImpl implements GenderPurchaseService{
    
    @Autowired
    private CustomerCrudService customerCrudService;

    @Override
    public List<Album> getGenderPurchases(String gender) {
        List<Album> albums = new ArrayList<Album>(); 
        
        List<Customer> customers = customerCrudService.findAll();
        for(int a =0; customers.size() > 0; a++)
        {
            if(customers.get(a).getDemographic().getGender().equalsIgnoreCase(gender))
            {
                List<Orders> orders = customers.get(a).getOrders();
                for(int b =0; orders.size() > 0; b++)
                {
                    List<OrderItem> items = orders.get(b).getItems();
                    for(int c=0; items.size() > 0; c++)
                    {
                        albums.add(items.get(c).getAlbum());
                    }
       
                    
                }
                
            }
        }
        
        
        return albums;
    }
    
}
